<?php defined('BASEPATH') || exit('No direct script access allowed');

/**
 * Building controller
 */
class Menu extends Api_Controller
{
    /**
     * @apiDefine Menu 菜单
     */
    function __construct()
    {
        // Construct the parent class
        parent::__construct();
        $this->load->model('menu_m');
    }

    /**
     * @api               {get} menu/index 底部菜单
     * @apiGroup          Menu
     * @apiName           menu/index
     * @apiVersion        1.0.0
     * @apiDescription    底部菜单
     * @apiSampleRequest https://api.bjxpel.cn/api/menu/index
     * @apiSuccess {String}  title 标题
     * @apiSuccess {String}   url 外链
     * @apiSuccessExample 成功响应
     *          {
     *           "message": "ok",
     *           "code": 200,
     *           "data": null
     *          }
     * @apiErrorExample   失败响应
     *            {
     *             "message": "err",
     *             "code": 0,
     *             "data": null
     *            }
     */
    public function index()
    {
        $menu = $this->menu_m->select();
        if (!$menu) {
            return $this->failure();
        }
        $list = [];
        foreach ($menu as $key => $val) {
            unset($val['pic_url']);
            unset($val['deleted']);
            $val['type_name'] = $val['type'] == 0 ? "联系我们" : "xpel资讯";
            if ($val['type'] == 0) {
                $list['about'][] = $val;
            } else {
                $list['news'][] = $val;
            }
        }
        return $this->success(['list' => $list]);
    }

}